package com.fjnldx.mes.controller.salaryReport;

import com.fjnldx.mes.domain.domainReq.IdList;
import com.fjnldx.mes.domain.domainReq.QuerySalaryReport;
import com.fjnldx.mes.domain.domainReq.QuerySalaryReportTemplate;
import com.fjnldx.mes.domain.domainReq.UpdateSalaryReportTemplate;
import com.fjnldx.mes.domain.domainRes.Result;
import com.fjnldx.mes.domain.pojo.VarietyParameters;
import com.fjnldx.mes.domain.pojo.VarietyParametersReq;
import com.fjnldx.mes.service.salaryReport.SalaryReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

@RestController
@RequestMapping("/salaryReport")
@Api(value = "薪资报表", tags = "薪资报表")
public class SalaryReportController {

    @Resource
    SalaryReportService salaryReportService;

    @PostMapping("/queryVarietyParameters")
    @ApiOperation(value = "公定参数-条件查询", notes = "公定参数-条件查询")
    public Result queryVarietyParameters(@RequestBody VarietyParametersReq params) {
        return salaryReportService.queryVarietyParameters(params);
    }

    @PostMapping("/addVarietyParameters")
    @ApiOperation(value = "公定参数-新增", notes = "公定参数-新增")
    public Result addVarietyParameters(@RequestBody VarietyParameters params) {
        return salaryReportService.addVarietyParameters(params);
    }

    @PostMapping("/deleteVarietyParameters")
    @ApiOperation(value = "公定参数-删除", notes = "公定参数-删除")
    public Result deleteVarietyParameters(@RequestBody IdList params) {
        return salaryReportService.deleteVarietyParameters(params);
    }

    @PostMapping("/updateVarietyParameters")
    @ApiOperation(value = "公定参数-修改", notes = "公定参数-修改")
    public Result updateVarietyParameters(@RequestBody VarietyParameters params) {
        return salaryReportService.updateVarietyParameters(params);
    }

    @PostMapping("/querySalaryReport")
    @ApiOperation(value = "查询薪资报表", notes = "查询薪资报表")
    public Result querySalaryReportXs(@Validated @RequestBody QuerySalaryReport data, Errors errors) {
        if (errors.hasErrors()) {
            return Result.error(Objects.requireNonNull(errors.getFieldError()).getDefaultMessage());
        }
        return salaryReportService.querySalaryReport(data);
    }

    @PostMapping("/queryTemplateFieldAttribution")
    @ApiOperation(value = "查询模板字段归属", notes = "查询模板字段归属")
    public Result queryTemplateFieldAttribution(@Validated @RequestBody QuerySalaryReportTemplate data, Errors errors) {
        if (errors.hasErrors()) {
            return Result.error(Objects.requireNonNull(errors.getFieldError()).getDefaultMessage());
        }
        return salaryReportService.queryTemplateFieldAttribution(data);
    }

    @PostMapping("/updateTemplateFieldAttribution")
    @ApiOperation(value = "修改模板字段归属", notes = "修改模板字段归属")
    public Result updateTemplateFieldAttribution(@Validated @RequestBody UpdateSalaryReportTemplate data, Errors errors) {
        if (errors.hasErrors()) {
            return Result.error(Objects.requireNonNull(errors.getFieldError()).getDefaultMessage());
        }
        return salaryReportService.updateTemplateFieldAttribution(data);
    }
}
